<div style="float:right;height:30px;">

</div>
<!-----------------filter form ----------------------------------->
<form action="<?= $base_url; ?>/cart/order/" method="post">

 <div class="orderMess" style="">  Thank you for your purchase with us. Your order will be delivered soon. Check ur mail for ur order details. </div>
     

<table class="carttable" style="font-size:17px;" cellpadding="0" cellspacing="0">
<tbody>
<tr class="cartHead">

<th class="tbname">&nbsp;</th>
<th class="tbname">Name</th>

<th class="tbname">Price(<img src="<?=$image_path?>Rs.png" height="10" width="10"/>)</th>
 
<th class="tbname">Quantity</th>
 
<th class="tbaction">Sub total(<img src="<?=$image_path?>Rs.png" height="10" width="10"/>)</th>
</tr>
<?php 
if(!empty($product)) 
{
	foreach($product as $key => $record) 
	{
		$style = (++$key%2) ? '' : 'alt'; 
?>	
	<tr class="<?php echo $style;?>">
	
        <td><?php $img = $record['id'].".".$record['image'];?>
         <img src="<?= $image_path; ?>products/<?=$img; ?>" height="50" width="50" class="thumb"/>
         <br/><a href="<?=$base_url;?>cart/remove_item/<?=$record['id'] ?>"  class="r_items"><span> remove item </span> </a>
         </td>
		<td><?php echo $record['name']?></td>
      
         <td><?php
		  if($record['special_cost'] >0)
		  {
		  echo $record['special_cost'];
		  $price  = $record['special_cost'];
		  }
		  else
		  {
		  echo $record['cost'];
		  $price  = $record['cost'];
		  }
		  ?>
          </td>
       
         <td> <?= $_SESSION['prod'][$record['id']]['qty']?>   </td>
		<td>
                <?php
				$rate      = $price * $_SESSION['prod'][$record['id']]['qty'];
				$total    += $rate;
		/*  if($record['special_cost'] >0)
		  echo $record['special_cost'];
		  else
		  echo $record['cost']?> */
		  echo  number_format($rate,2,'.','');
		  //number_format($info['cost'],2,'.',''
		  ?>

	
		</td>
	</tr>
    
<?php 
	}
	?>
	<tr>
    <td colspan="4" align="right"> &nbsp;&nbsp;
     &nbsp;&nbsp;&nbsp;<b>Total:</b>
    </td>
    <td><?=number_format($total,2,'.','');?>
    </td>
    </tr>
   
    <?php
	
	$mylogin                  = $this->session->userdata('mylogin');
//print_r($mylogin);
		$data['user_id']          =  $mylogin['id'];
		$data['total_amount']     =  $total;
		$data['status']           =  'new';
		$data['created']          =  date('Y-m-d');
		$data['order_number']     =  date('d').date('m');
		//print_r($data);
		$status                    = $this->order_model->add($data);

        foreach($product as $key => $record)
		{
			$data1['order_id']       = $status['id'];
			$data1['user_id']        = $mylogin['id'];
			$data1['product_id']     = $record['id'];
			
			if($record['special_cost'] > 0)
			{
				$data1['unit_amount']    = $record['special_cost'];
			}
			else
			{
				$data1['unit_amount']    = $record['cost'];
			}
			$data1['quantity']       		= $_SESSION['prod'][$record['id']]['qty'];
			$data1['total']          		= $data1['quantity'] * $data1['unit_amount'] ;
			$order_status                   = $this->order_product_model->add($data1);
		}
	
} else {
?>
<tr><td colspan="6">No products available</td></tr>
<?php }
if(!empty($product)) 
{
	$total=0;
$message = "<table class='carttable' style='font-size:17px;' cellpadding='0' cellspacing='0'>
<tbody>
<tr class='cartHead'>

<th class='tbname'>&nbsp;</th>
<th class='tbname'>Name</th>

<th class='tbname'>Price(<img src='".$image_path."Rs.png' height='10' width='10'/>)</th>
 
<th class='tbname'>Quantity</th>
 
<th class='tbaction'>Sub total(<img src='".$image_path."Rs.png' height='10' width='10'/>)</th>
</tr>";


	foreach($product as $key => $record) 
	{
		$style = (++$key%2) ? '' : 'alt'; 
?>	
<?php 	$message .="<tr>
	
        <td>";
		$img = $record['id'].".".$record['image'];
         $message .= "
         <br/>
         </td>
		<td>". $record['name']."</td>
      
         <td>";
		 
		  if($record['special_cost'] >0)
		  {
		  $message   .= $record['special_cost'];
		  $price  = $record['special_cost'];
		  }
		  else
		  {
		  $message   .= $record['cost'];
		  $price      = $record['cost'];
		  }
		  
          $message  .= "</td>";
       
          $message   .=  "<td> ". $_SESSION['prod'][$record['id']]['qty']."   </td>
		<td>";
				$rate      = $price * $_SESSION['prod'][$record['id']]['qty'];
				$total    += $rate;
		/*  if($record['special_cost'] >0)
		  echo $record['special_cost'];
		  else
		  echo $record['cost']?> */
		  $message .=  number_format($rate,2,'.','');
		  //number_format($info['cost'],2,'.',''
		  

	
		$message   .="</td>	</tr>";
    

	}
	$message   .= "<tr>
    <td colspan='4' align='right'> &nbsp;&nbsp;
     &nbsp;&nbsp;&nbsp;<b>Total:</b>
    </td>
    <td>".number_format($total,2,'.','')."
    </td>
    </tr>";
	//print_r($mylogin);
	$headers  = 'MIME-Version: 1.0' . "\r\n";
	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
	$headers .= 'From: Olive super market <megilatechnocorporators@gmail.com>' . "\r\n";
    //echo $message;
	$to       = $mylogin['email'];
	$subject  = "Your order datails";
	//echo $message;
	mail($to,$subject,$message,$headers);
   
}


?>
</tbody>
</table>
<div class="spacer10 rightText">
<?php 	echo $this->pagination->create_links();?>
</div>
         
          

</form>